{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "incoming-ethernet",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/find-and-replace-pattern\n",
    "\n",
    "\n",
    "Runtime: 0 ms, faster than 100.00% of C++ online submissions for Find and Replace Pattern.\n",
    "Memory Usage: 8.6 MB, less than 54.27% of C++ online submissions for Find and Replace Pattern.\n",
    "\n",
    "\n",
    "```cpp\n",
    "#include <vector>\n",
    "#include <algorithm>\n",
    "#include <map>\n",
    "#include <string>\n",
    "\n",
    "\n",
    "using namespace std;\n",
    "\n",
    "class Solution {\n",
    "public:\n",
    "    vector<string> findAndReplacePattern(vector<string>& words, string pattern) {\n",
    "        //7:28\n",
    "        vector<string> results;\n",
    "        auto the_target = get_pattern(pattern);\n",
    "        for (const auto & word : words) {\n",
    "            auto target = get_pattern(word);\n",
    "            if (target == the_target) {\n",
    "                results.push_back(word);\n",
    "            }\n",
    "        }\n",
    "        return results;\n",
    "        //7:36\n",
    "    }\n",
    "    vector<int> get_pattern(string s) {\n",
    "        map<char, int> m;\n",
    "        int i = 0;\n",
    "        vector<int> list;\n",
    "        for (const auto & c : s) {\n",
    "            if (m.find(c) == m.end()) {\n",
    "                m.insert(pair<char, int>{c, i});\n",
    "                i+=1;\n",
    "            }\n",
    "            list.push_back(m[c]);\n",
    "        }\n",
    "        return list;\n",
    "    }\n",
    "};\n",
    "// made by yingshaoxo: https://github.com/yingshaoxo\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "civilian-johns",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "C++17",
   "language": "C++17",
   "name": "xcpp17"
  },
  "language_info": {
   "codemirror_mode": "text/x-c++src",
   "file_extension": ".cpp",
   "mimetype": "text/x-c++src",
   "name": "c++",
   "version": "17"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
